Plugin API: New Features

Sergei Golubchik
VP Architecture
Monty Program Ab

Why to Bother

Why you may need to extend MySQL

Ancient History

Traditional ways of extending MySQL

Modern History

Plugin types in 5.1

Modern History

Plugin API features in 5.1

Plugin administration

New Plugin type: Audit

Audit Events

Use cases

Audit Plugin Example

void security_violations(MYSQL_THD thd, const struct mysql_event *event)
{
  struct tm t;
  const struct mysql_event_general *ev = event;
  switch (ev->general_error_code) {
  case ER_ACCESS_DENIED_ERROR:
  case ER_DBACCESS_DENIED_ERROR:
  /* more error codes can go here */
    localtime_r(&ev->general_time, &t);
    pthread_mutex_lock(&lock);
    fprintf(logfile, "%04d-%02d-%02d %2d:%02d:%02d [%s] ERROR %d: %s\n",
            t.tm_year + 1900, t.tm_mon + 1,
            t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
            ev->general_user, ev->general_error_code,
            ev->general_command);
    pthread_mutex_unlock(&lock);
  }
}

Pluggable Authentication

Client side plugins

Usage

GRANT ALL PRIVILEGES ON *.* TO foo@bar 
                            IDENTIFIED VIA two_questions USING 'secret';
CREATE USER serg IDENTIFIED VIA socket_peercred;
MariaDB [test]> SELECT plugin_name, plugin_type, plugin_library,
            --> plugin_description FROM INFORMATION_SCHEMA.PLUGINS
            --> WHERE plugin_type='authentication';
+-----------------------+----------------+----------------------------------+
| PLUGIN_NAME           | PLUGIN_LIBRARY | PLUGIN_DESCRIPTION               |
+-----------------------+----------------+----------------------------------+
| mysql_native_password | NULL           | Native MySQL authentication      |
| mysql_old_password    | NULL           | Old MySQL-4.0 authentication     |
| socket_peercred       | auth_socket.so | Unix Socket based authentication |
| two_questions         | dialog.so      | Dialog plugin demo 1             |
| three_attempts        | dialog.so      | Dialog plugin demo 2             |
+-----------------------+----------------+----------------------------------+

Interface details

Automatic plugin negotiation

S/Key

$ skey -n 5 98 janu76882
Reminder - Do not use this program while logged in via telnet or rlogin.
Enter secret password: qwertyuiop
 94: OLIN NEAR DUG LETS SITS GOLD 
 95: BLAT BONY RUIN SCAR RACE WHY 
 96: RICE DANG JIM BOON NEAR TRAG 
 97: MOS BLOT QUAD JANE HUGE FOOL 
 98: HERB JESS BLAB VERB DAWN BEN 

Authentication Plugin Example

static int skey_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
{
  unsigned char *pkt;
  int pkt_len;
  struct skey mp;
  char buf[SKEY_MAX_CHALLENGE+3];

  buf[0] = 2; /* ordinary question */
  if (skeychallenge(&mp, info->user_name, buf+1, SKEY_MAX_CHALLENGE) < 0)
    return CR_ERROR;
  strcat(buf, ":");
  if (vio->write_packet(vio, buf, strlen(buf)))
    return CR_ERROR;
  if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
    return CR_ERROR;
  info->password_used = 1;
  return skeyverify(&mp, pkt) ? CR_ERROR : CR_OK;
}

Demo

$ mysql --user=sktest
[mariadb] otp-md5 98 janu76882: HERB JESS BLAB VERB DAWN BEN
Your MariaDB connection id is 3
Server version: 5.2.0-MariaDB-alpha-debug Source distribution
MariaDB [test]> quit
Bye

$ mysql --user=sktest
[mariadb] otp-md5 97 janu76882: MOS BLOT QUAD JANE HUGE FOOL
Your MariaDB connection id is 4
Server version: 5.2.0-MariaDB-alpha-debug Source distribution
MariaDB [test]> quit
Bye

$ mysql --user=sktest
[mariadb] otp-md5 96 janu76882: MOS BLOT QUAD JANE HUGE FOOL
ERROR 1045 (28000): Access denied for user 'sktest'@'localhost' (using password: YES)

New Plugin type: Replication

Use cases

Server Services for Plugins

Server Services for Plugins

CREATE TABLE extension

CREATE TABLE extension

 

Questions ?